package team.southcat.wsyygh.hospital.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import team.southcat.wsyygh.common.result.Result;
import team.southcat.wsyygh.common.util.AdminInfoUtil;
import team.southcat.wsyygh.hospital.service.DoctorService;
import team.southcat.wsyygh.model.pojo.hospital.Doctor;
import team.southcat.wsyygh.model.pojo.hospital.DoctorVo;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author QiuSiYi
 * @since 2023-04-20
 */
@Api(tags = "医生管理接口")
@RestController
@RequestMapping("/admin/hospital/doctor")
public class DoctorController {

    @Resource
    private DoctorService doctorService;

    @ApiOperation("分页查询医生列表")
    @GetMapping("/getDoctorPageList/{page}/{limit}")
    public Result getDoctorPageList(@PathVariable int page, @PathVariable int limit, DoctorVo doctorVo, HttpServletRequest request){
        String adminId = AdminInfoUtil.getAdminId(request);
        Page pageResult = doctorService.getDoctorPageList(page,limit,doctorVo,adminId);
        return Result.ok(pageResult);
    }

    @ApiOperation("根据科室查医生")
    @GetMapping("/getByDepartmentId/{id}")
    public Result getByDepartmentId(@PathVariable int id){
        LambdaQueryWrapper<Doctor> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Doctor::getDepartmentId,id);
        List<Doctor> doctors = doctorService.list(queryWrapper);
        return Result.ok(doctors);
    }

    @ApiOperation("查询所有医生")
    @GetMapping("/getAllDoctor")
    public Result getAllDoctor(HttpServletRequest request){
        String adminId = AdminInfoUtil.getAdminId(request);
        List<Doctor> doctors = doctorService.getList(adminId);
        return Result.ok(doctors);
    }

    @ApiOperation("根据id删除医生和医生排班信息")
    @DeleteMapping("/deleteDoctorById/{id}")
    public Result deleteDoctorById(@PathVariable int id){
        Result result = doctorService.deleteDoctorById(id);
        return result;
    }

    @ApiOperation("批量删除医生")
    @DeleteMapping("/batchDeleteDoctorByIds")
    public Result batchDeleteDoctorByIds(@RequestBody List<Integer> ids){
        Result result = doctorService.batchDeleteDoctorByIds(ids);
        return result;

    }

    @ApiOperation("添加医生")
    @PostMapping("/addDoctor")
    public Result addDoctor(@RequestBody Doctor doctor){
        Result result = doctorService.addDoctor(doctor);
        return  result;
    }

    @ApiOperation("修改医生")
    @PostMapping("/updataDoctor")
    public Result updataDoctor(@RequestBody Doctor doctor){
        Result result = doctorService.updataDoctor(doctor);
        return  result;
    }

    @ApiOperation("根据id查询医生信息")
    @GetMapping("/getDoctorById/{id}")
    public Result getDoctorById(@PathVariable Integer id){
        Result result =  doctorService.getDoctorById(id);
        return result;
    }

    @GetMapping("/getDoctorByName")
    public Result getDoctorByName(@RequestBody List<String> doctorName){
        List<Doctor> doctors = doctorService.getDoctorByName(doctorName);
        return Result.ok(doctors);
    }

    @GetMapping("/getDoctorByDepartmentIds")
    public Result getDoctorByDepartmentIds(@RequestBody List<Long> departmentIds){
        List<Doctor> doctors = doctorService.getDoctorByDepartmentIds(departmentIds);
        return Result.ok(doctors);
    }
}

